Page({

    /**
     * 页面的初始数据
     */
    data: {
        sign:'1',
        id:'',
      title:'国家一级心理咨询师',
      title1:'压力情绪',
      title2:'2019-05-21 09:30',
      shuoming:'我最近心情很郁闷，总是感觉胸闷，失眠。想咨询如何缓解心理压力......',
      date: '',
      value:'',
      show: false,
      show1:false,
      show2:false,
      actions: [
          {
            name: '国家一级心理咨询师',
          },
          {
            name: '国家二级心理咨询师',
          },
          {
            name: '国家三级心理咨询师',
          },
      ],
      buttonLists:[
          "家庭关系","亲子关系","婚恋感情","生活问题","个体咨询","人际关系","压力情绪","儿童心理","青少年","成年人","职场问题","心理危机干预","精神疾病治疗","抑郁症","老年心理","忧郁症","成瘾性问题","性相关问题"
      ],
      
    selectBq:'',
    selectedButtonIndexes1: [],
    colors1: [],
    bacs1:[],
    },
  
    showPopup() {
      this.setData({ show: true });
    },
    showSheet() {
      this.setData({ show1: true });
    },
  
    onClose() {
      this.setData({ show: false });
      this.setData({show1:false});
      this.setData({show2:false});
    },
  
    onSelect(event) {
        this.setData({
            title:event.detail.name
        })
    },

    selectButton(e){
        const index = e.currentTarget.dataset.index;
        const selectedButtonIndexes1 = this.data.selectedButtonIndexes1;
        if (selectedButtonIndexes1.includes(index)) {
          // 如果按钮已被选中，再次点击则取消选中并恢复颜色为白色
          selectedButtonIndexes1.splice(selectedButtonIndexes1.indexOf(index), 1);
          const newColors = this.data.colors1.map(() => '');
          const newBacs=this.data.bacs1.map(()=>'');
          this.setData({
            selectedButtonIndexes1,
            colors1: newColors,
            bacs1:newBacs
          });
        } else {
          // 如果按钮未被选中，点击后设置颜色为蓝色并记录选中状态
          selectedButtonIndexes1.push(index);
          const newColors = this.data.colors1.map(() => '');
          newColors[index] = 'white';
          const newBacs=this.data.bacs1.map(()=>'');
          newBacs[index] = '#87d2f8';
          this.setData({
            selectedButtonIndexes1,
            colors1: newColors,
            bacs1:newBacs,
            selectBq:e.currentTarget.dataset.button,
            title1:e.currentTarget.dataset.button,
          });
        }
      },
      reset(e){
        const title="国家一级心理咨询师";
        const title1="压力情绪";
        this.setData({
              title:title,
              selectedButtonIndexes1: [],
              title1:title1,
              colors1: [],
              bacs1: [],
              title2:'2019-05-21 09:30',
              shuoming:'我最近心情很郁闷，总是感觉胸闷，失眠。想咨询如何缓解心理压力......',
        })
      },

      confirm(e){
      const yuyueTime=this.data.title2;
      const yuyueUid=this.data.id;
      const yuyueType=this.data.title1;
      const yuyueContent=this.data.shuoming;
      const gradeName=this.data.title;
      
      wx.request({
        url: 'http://localhost:8080/yuyue/insert',
        method:"GET",
        data:{
            yuyueTime:yuyueTime,
            yuyueUid:yuyueUid,
            yuyueType:yuyueType,
            yuyueContent:yuyueContent,
        },
        success:(res)=>{
            console.log(res);
            let url='?yuyueTime=' + yuyueTime + '&yuyueUid=' + yuyueUid + '&yuyueType=' + yuyueType + '&yuyueContent=' + yuyueContent;
            wx.navigateTo({
                url: '/pages/tuijianResult_lfy/tuijianResult_lfy'+url+'&gradeName='+gradeName+'&sign'+sign,
                success:function(res){
                    console.log("跳转成功");
                    },fail:function(res){
                    console.log("跳转失败");
                    },complete:function(res){
                    console.log("跳转完成....");
                    }
            })
        }})
      },
  
    onDisplay() {
      this.setData({ show2: true });
    },
    formatDate(date) {
      date = new Date(date);
      return `${date.getYear()+1900}-${date.getMonth() + 1}-${date.getDate()}`;
    },
    onConfirm(event) {
      this.setData({
        show2: false,
        title2: this.formatDate(event.detail),
      });
    },

    shuoming(){
        wx.navigateTo({
          url: '/pages/shuoming_lfy/shuoming_lfy',
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var app = getApp();
        var userInfo= app.globalData.userInfo;
        console.log(userInfo[0].id);
        this.setData({
            id:userInfo[0].id
        })
    },
  
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
  
    },
  
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
  
    },
  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
  
    },
  
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
  
    },
  
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
  
    },
  
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
  
    },
  
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
  
    }
  })